package com.mos.dao.impl;

import com.mos.base.sql.BaseDaoImpl;
import com.mos.base.sql.Page;
import com.mos.dao.UserDao;
import com.mos.entity.User;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Package Name: com.mos.dao.impl
 * User: grq
 * Date: 2016/3/24
 * Time: 14:57
 * Description:some des here!
 */
@Repository
public class UserDaoImpl extends BaseDaoImpl implements UserDao {

    public void save(User user) {
        String sql = "insert into t_user(name,password) values(?,?)";
        Object[] params = {user.getName(),user.getPassword()};
//        jdbcTemplate.update(sql,params);
        super.addOrUpdateOrDelete(sql,params,User.class);
    }

    public Page<User> queryPage(Integer pageNo, Integer pageSize, Object[] params) {
        String sql = "select t.id,t.name,t.password from t_user t ";
        return super.queryPagination(sql,params,pageNo,pageSize,User.class);
    }

    public User findById(int id) {
        String sql = "select * from t_user where id = ?" ;
        User user = super.findForObject(sql,new Object[]{id},User.class);
        return user;
    }

    public Map<String, Object> find(int id) {
        String sql = "select t.name,t.password from t_user t where t.id = ? ";
        return super.find(sql,new Object[]{id});
    }

    public List<Map<String, Object>> queryList(String name) {
        String sql = "select t.name,t.password from t_user t where t.name like ? ";
        return super.queryList(sql,new Object[]{"%"+name+"%"});
    }
}
